import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:hbtrans_flutter/apis.dart';
import 'package:hbtrans_flutter/beans/signuporder_bean.dart';
import 'package:hbtrans_flutter/const.dart';
import 'package:hbtrans_flutter/routes.dart';
import 'package:hbtrans_flutter/utils/mydio.dart';
import 'package:hbtrans_flutter/utils/mydio.dart' as prefix0;
class ModifyOrder extends StatefulWidget {
  final orderId;
  const ModifyOrder({Key key, this.orderId}) : super(key: key);
  @override
  _ModifyOrderState createState() => _ModifyOrderState();
}

class _ModifyOrderState extends State<ModifyOrder> {

  SignUpOrderBean signUpOrderBean;
  Map<String,dynamic> userData=Map();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    signuporder(widget.orderId);
  }


  void signuporder(String id) async {
    MyDio.getInstance().clearInstance();
    MyDio.getInstance(url: Const.TRANS_SERVER_PATH_NEW3).get('${Apis.signUpOrder}$id', (data) {
      print(data);
//      if (loadingDialog != null) {
//        loadingDialog = null;
//        Navigator.pop(context);
//      }
      setState(() {
         signUpOrderBean = SignUpOrderBean.fromJson(data);
      });
    });
  }

  void _updateOrder(){
    MyDio.getInstance().clearInstance();
    userData['orderId']=widget.orderId;
    MyDio.getInstance(url: Const.TRANS_SERVER_PATH_NEW3).post(Apis.updateOrder,
            (data) {
          print(data);
//          String route = '${Routes.mainPage}';
//          Routes.router.navigateTo(context, route,
//              replace: true, transition: TransitionType.fadeIn);
        }, params: userData);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('报名学车'),
        centerTitle: true,
        actions: <Widget>[
          Center(
              child: GestureDetector(
                onTap: () {
                   _updateOrder();
                },
                child: Text(
                  '修改',
                  style: TextStyle(fontSize: 16, color: Colors.white),
                ),
              ))
        ],
      ),
      body: ListView(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.fromLTRB(15, 20, 15, 9),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  signUpOrderBean.classname,
                  style: TextStyle(fontSize: 14, color: Color(0xff333333)),
                ),
                SizedBox(
                  height: 7,
                ),
                Text(
                  '车型：c1',
                  style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                ),
                SizedBox(
                  height: 7,
                ),
                Text(
                  '￥'+signUpOrderBean.price,
                  style: TextStyle(fontSize: 18, color: Color(0xffF44336)),
                ),
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '学员姓名',
                  style: TextStyle(fontSize: 13, color: Color(0xff666666)),
                ),
                Expanded(
                    child:  TextFormField(
                      textAlign: TextAlign.right,
                  style: TextStyle(fontSize: 13, color: Colors.grey),
                  onChanged: (value){
                    userData['username']=value;
                  },
                      initialValue: signUpOrderBean.username==null?'暂无':signUpOrderBean.username,
                  decoration: InputDecoration(
                    border: InputBorder.none, //去掉下划线
                    hintStyle: TextStyle(fontSize: 13, color: Color(0xff666666)),
                ),)
                )
              ]
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '身份证号',
                  style: TextStyle(fontSize: 13, color: Color(0xff666666)),
                ),
                Expanded(
                    child:  TextFormField(
                      textAlign: TextAlign.right,
                      style: TextStyle(fontSize: 12, color: Colors.grey),
                      onChanged: (value){
                        userData['idcard']=value;
                      },
                      initialValue: signUpOrderBean.idcard==null?'暂无':signUpOrderBean.idcard,
                      decoration: InputDecoration(
                        border: InputBorder.none, //去掉下划线
                        hintStyle: TextStyle(fontSize: 12, color: Color(0xff999999)),
                      ),)
                )
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
          Padding(
            padding: EdgeInsets.all(15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '联系电话',
                  style: TextStyle(fontSize: 13, color: Color(0xff666666)),
                ),
                Text(
                  signUpOrderBean.phone,
                  style: TextStyle(fontSize: 12, color: Color(0xff666666)),
                ),
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
          Padding(
            padding: EdgeInsets.all(15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '商品合计',
                  style: TextStyle(fontSize: 13, color: Color(0xff666666)),
                ),
                Text(
                  '￥'+signUpOrderBean.tolalprice,
                  style: TextStyle(fontSize: 12, color: Color(0xff666666)),
                ),
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
          Padding(
            padding: EdgeInsets.all(15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Image.asset('images/jd.png',width: 26,height: 26,),
                    SizedBox(
                      width: 10,
                    ),
                    Text(
                      '京东白条',
                      style: TextStyle(fontSize: 14, color: Color(0xff666666)),
                    ),
                  ],
                ),
                Image.asset('images/icon_xuanzhong.png',width: 20,height: 20,),
              ],
            ),
          ),
          Container(
            height: 1,
            color: Color(0xffE4E4E4),
          ),
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 50,
          child: Row(
            children: <Widget>[
              Expanded(
                  flex: 3,
                  child: Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(left: 15),
                    child: InkWell(
                      onTap: () {
                      },
                      child: Text(
                        signUpOrderBean.tolalprice,
                        style:
                        TextStyle(color: Color(0xff333333), fontSize: 14.0),
                      ),
                    ),
                  )),
              Expanded(
                flex: 1,
                child: Container(
                    color: Colors.red,
                    child: InkWell(
                        onTap: () {},
                        child: Center(
                          child: Text(
                            '付款',
                            style:
                            TextStyle(color: Colors.white, fontSize: 14.0),
                          ),
                        ))),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
